// Copyright (C) 2016 Tim Disney. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Invalid unicode escape sequence in tagged template literals are allowed
esid: sec-template-literal-lexical-components
---*/

function Test() {
    (strs => {
      assert.sameValue(strs[0], undefined, 'Cooked template value should be undefined for illegal escape sequences');
      assert.sameValue(strs.raw[0], '\\01');
    })`\01`;

    (strs => {
      assert.sameValue(strs[0], undefined, 'Cooked template value should be undefined for illegal escape sequences');
      assert.sameValue(strs.raw[0], '\\1');
    })`\1`;

    (strs => {
      assert.sameValue(strs[0], undefined, 'Cooked template value should be undefined for illegal escape sequences');
      assert.sameValue(strs.raw[0], '\\8');
    })`\8`;

    (strs => {
      assert.sameValue(strs[0], undefined, 'Cooked template value should be undefined for illegal escape sequences');
      assert.sameValue(strs.raw[0], '\\9');
    })`\9`;

    (strs => {
      assert.sameValue(strs[0], undefined, 'Cooked template value should be undefined for illegal escape sequences');
      assert.sameValue(strs.raw[0], '\\xg');
    })`\xg`;

    (strs => {
      assert.sameValue(strs[0], undefined, 'Cooked template value should be undefined for illegal escape sequences');
      assert.sameValue(strs.raw[0], '\\xAg');
    })`\xAg`;

    (strs => {
      assert.sameValue(strs[0], undefined, 'Cooked template value should be undefined for illegal escape sequences');
      assert.sameValue(strs.raw[0], '\\u0');
    })`\u0`;

    (strs => {
      assert.sameValue(strs[0], undefined, 'Cooked template value should be undefined for illegal escape sequences');
      assert.sameValue(strs.raw[0], '\\u0g');
    })`\u0g`;

    (strs => {
      assert.sameValue(strs[0], undefined, 'Cooked template value should be undefined for illegal escape sequences');
      assert.sameValue(strs.raw[0], '\\u00g');
    })`\u00g`;

    (strs => {
      assert.sameValue(strs[0], undefined, 'Cooked template value should be undefined for illegal escape sequences');
      assert.sameValue(strs.raw[0], '\\u000g');
    })`\u000g`;

    (strs => {
      assert.sameValue(strs[0], undefined, 'Cooked template value should be undefined for illegal escape sequences');
      assert.sameValue(strs.raw[0], '\\u{g');
    })`\u{g`;

    (strs => {
      assert.sameValue(strs[0], undefined, 'Cooked template value should be undefined for illegal escape sequences');
      assert.sameValue(strs.raw[0], '\\u{0');
    })`\u{0`;

    (strs => {
      assert.sameValue(strs[0], undefined, 'Cooked template value should be undefined for illegal escape sequences');
      assert.sameValue(strs.raw[0], '\\u{10FFFFF}');
    })`\u{10FFFFF}`;

    ((strs, val) => {
      assert.sameValue(val, 'inner');
      assert.sameValue(strs[0], undefined, 'Cooked template value should be undefined for illegal escape sequences');
      assert.sameValue(strs.raw[0], '\\u{10FFFFF}');

      assert.sameValue(strs[1], 'right');
      assert.sameValue(strs.raw[1], 'right');
    })`\u{10FFFFF}${'inner'}right`;
}

// preheat
const NUMBER_OF_PREHEAT = 1;
for (let i = 0; i < NUMBER_OF_PREHEAT; i++) {
    Test();
}

ArkTools.jitCompileAsync(Test);
assert.sameValue(ArkTools.waitJitCompileFinish(Test), true, '[JIT] JIT disabled.');

// test
const NUMBER_OF_TEST = 1; // or 2
for (let i = 0; i < NUMBER_OF_TEST; i++) {
    Test();
}
